package com.hongxun.budget.ui.dialog;

import android.view.View;
import android.widget.EditText;

import com.hongxun.budget.R;
import com.hongxun.budget.utils.KeyBoardUtils;
import com.hongxun.budget.utils.T;
import com.hongxun.greenentity.sg.CGoodsDetailEntity;
import com.hongxun.interfaces.ResponseListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/7/25.
 */

public class InputDialog3 extends BaseCenterFragmentDialog {

    @BindView(R.id.et1)
    EditText et1;
    @BindView(R.id.et2)
    EditText et2;
    @BindView(R.id.et3)
    EditText et3;
    @BindView(R.id.et4)
    EditText et4;

    ResponseListener listener;
    CGoodsDetailEntity bean;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_input3;
    }

    @Override
    protected void initViews() {
        bean = (CGoodsDetailEntity) getArguments().getSerializable("bean");
        et1.setText(bean.getGDNum() + "");
        et2.setText(bean.getGDBusine());
        et3.setText(bean.getGDPrice()+"");
        et4.setText(bean.getGDWeight()+"");
        KeyBoardUtils.openKeybord(et1, getActivity());
    }

    public InputDialog3 setListener(ResponseListener listener) {
        this.listener = listener;
        return this;
    }

    @OnClick({R.id.cancel, R.id.confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel:
                dismiss();
                break;
            case R.id.confirm:
                String ghs1 = et1.getText().toString();
                String ghs2 = et2.getText().toString();
                String ghs3 = et3.getText().toString();
                String ghs4 = et4.getText().toString();
                double count1;
                try {
                    count1 = Double.parseDouble(ghs1);
                } catch (NumberFormatException e) {
                    T.showShort(context, "到货数量请输入数字");
                    return;
                }
                bean.setGDNum(count1);
                bean.setGDBusine(ghs2);
                double count2;
                try {
                    count2 = Double.parseDouble(ghs3);
                } catch (NumberFormatException e) {
                    T.showShort(context, "购置单价请输入数字");
                    return;
                }
                bean.setGDPrice(count2);
                double count3;
                try {
                    count3 = Double.parseDouble(ghs4);
                } catch (NumberFormatException e) {
                    T.showShort(context, "单重(kg)请输入数字");
                    return;
                }
                bean.setGDWeight(count3);
                listener.response(bean);
                KeyBoardUtils.closeKeybord(et4, getActivity());
                dismiss();
                break;
        }
    }
}
